Skip to content

Refactor (packages/desktop/src/main/sidecar.ts): Function with many returns - #46

Open
ammarri14 wants to merge 5 commits into
CMU-17313Q:mainfrom
ammarri14:refactor/sidecar-parse-command
Open

Refactor (packages/desktop/src/main/sidecar.ts): Function with many returns#46
ammarri14 wants to merge 5 commits into
CMU-17313Q:mainfrom
ammarri14:refactor/sidecar-parse-command

Conversation

@ammarri14

@ammarri14 ammarri14 commented Sep 3, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #44

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Qlty flagged parseCommand in sidecar.ts:130 with 8 returns

Collapsed four typeof guards into own combined condition which made it gofrom 8 returns to 5 which cleared the smell

Moved the function into a new sidecar-command.ts.
Because sidecar.ts runs electron code as soon as it is imported which fails outside he app hence a test couldn't import it

sidecar.ts imports parseCommand from the new module

How did you verify your code works?

Added sidecar-command.test.ts, it had 7 tests and 17 assertions
They cover parseCommand when input is not an object, the stop command, an unknown command type, the four required fields missing, each field with the wrong type, and a valid start command.

100% function and line coverage on the sidecar-command.ts file

it had 59 pass and 0 fail, it was 52 before. The 52 that already existed still pass, which shows that nothing broke.

bunx tsc --noEmit is clean for both

Qlty before and after code blocks:
Before

packages/desktop/src/main/sidecar.ts
 130  Function with many returns (count = 8): parseCommand
  91  Found 19 lines of identical code in 2 locations (mass = 128)
        also found at packages/desktop/src/main/index.ts

After

packages/desktop/src/main/sidecar.ts
  80  Found 19 lines of identical code in 2 locations (mass = 128)
        also found at packages/desktop/src/main/index.ts

The 698 warning and 2 errors from bun lint are already in other packages not from the change and neither sidecar file shows any lint output.

Added a CI test task for the desktop package. I pointed it at my test file because another test in that folder was already broken on CI.

Screenshots / recordings

bun test coverage opencode bun lint opencode

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P1B: Refactor (packages/desktop/src/main/sidecar.ts:130): Function with many returns (count = 8): parseCommand

1 participant